<?php

namespace Home\Controller;

use OT\DataDictionary;

/**
 * 微信控制器
 */
class WeixinNewController extends HomeController {
	private $_token = 'chenll'; // 填写你设定的key,微信公众平台填写的key
	private $_APPID ="wxcc3cb431ddc674c9";
	private $_APPSECRET="ca8b60de5051895a1a3702b21cc2a4ad";
	public function index() {
		return;
	}
	public function dowx() {
		$options = array (
			'token' => $this->_token,
			'appid' => $this->_APPID,
			'appsecret' => $this->_APPSECRET
		); // 填写你设定的key
		$weObj = new Wechat ( $options );
		$weObj->valid ();
		$type = $weObj->getRev ()->getRevType ();
		switch ($type) {
			case Wechat::MSGTYPE_TEXT :
				$content = $weObj->getRevContent ();
				$string = $this->dealText ( $content ); // 自定义
				$weObj->text ( $string )->reply ();
				exit ();
				break;
			case Wechat::MSGTYPE_EVENT :
				return '事件回复'; // //暂无功能
				break;
			case Wechat::MSGTYPE_IMAGE :
				$url = $weObj->getRevPic ();
				$wxuid = $weObj->getRevFrom ();
				$text = $this->dealImage ( $url, $wxuid ); // 自定义
				$weObj->text ( $text )->reply ();
				break;
			default :
				$string = $this->dealText ( 'HELP' );
				$weObj->text ( $string )->reply ();
		}
	}
	
	/**
	 * 处理文本消息
	 */
	protected function dealText($content) {
		$content = strtoupper ( $content );
		if ('HELP' == $content || '?' == $content || '？' == $content) {
			return $str = ' ZT+订单编号>查询订单状态;
                    WL+订单编号>查询订单物流;
                    TK+订单编号>查询退款进度;
                   	 图片>上传图片;
                    help>查看帮助;';
		}
		if (false !== strpos ( $content, 'ZT' )) {
			return '查询订单状态';
		}
		if (false !== strpos ( $content, 'WL' )) {
			return '查询订单物流';
		}
		if (false !== strpos ( $content, 'TK' )) {
			return '查询退款进度';
		}
		return "您可以发送【help】或者【?】来查看帮助！";
	}
}